/**
 * @a https://leetcode.cn/problems/teemo-attacking/
 */

#include "common.h"

class Solution
{
public:
    int findPoisonedDuration(vector<int> &timeSeries, int duration)
    {
        if(duration == 0) return 0;
        int poison_duration = 0;
        int lastend = 0;
        for(auto timepoint : timeSeries)
        {            
            int end = timepoint + duration;
            poison_duration += (timepoint > lastend) ? duration : end - lastend;
            lastend = end;
        }
        return poison_duration;
    }
};